package com.tms.app.tms.ui;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;

import com.tms.app.tms.app.Constant;
import com.tms.app.tms.bean.Fee;
import com.tms.app.tms.ui.base.ui.BaseListActivity;
import com.tms.app.tms.R;
import com.tms.app.tms.adapter.FeeInfoAdapter;
import com.tms.app.tms.ui.base.view.IListView;
import com.tms.app.tms.ui.feeinfo.FeeInfoPresenter;
import com.tms.app.tms.widget.CustomLoadMoreView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/10/28 0028.
 */

public class FeeInfoAC extends BaseListActivity  implements IListView {
    @BindView(R.id.button_send)
    Button buttonSend;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.swipeLayout)
    SwipeRefreshLayout swipeLayout;
    private CustomLoadMoreView customLoadMoreView;
    FeeInfoPresenter presenter;
    private int planId;
    private int waybillExecId;  // 与 planId 只能同时存在一个
    private int showType=0; //0 费用详情 不可操作  1 异常费用详情
    private String waybillNo;
    private int planIdShowType;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_layout_fee_info);
        ButterKnife.bind(this);
        presenter=new FeeInfoPresenter();
        presenter.setiView(this);
        initView();
        setToolBarTitle("费用详情",-1, -1);
        planId = getIntent().getIntExtra("planId", -1);
        showType=getIntent().getIntExtra("showType",0);
        waybillExecId=getIntent().getIntExtra("waybillExecId",-1);
        waybillNo=getIntent().getStringExtra("waybillNo");
        planIdShowType=getIntent().getIntExtra("planIdShowType",-1);
        presenter.setPlanIdShowType(planIdShowType);
        if (showType==0){//0 费用详情 不可操作  1 异常费用详情
            presenter.getData(token,planId);
            showLoadingDialog();
        }else {
            presenter.getExceptionFeeList(token,waybillExecId);
            showLoadingDialog();
        }


    }



    public void initView() {
        swipeLayout.setColorSchemeColors(Color.rgb(47, 223, 189));
        swipeLayout.setOnRefreshListener(presenter);
        customLoadMoreView = new CustomLoadMoreView();
        adapter = new FeeInfoAdapter();
        adapter.setLoadMoreView(customLoadMoreView);
        adapter.setOnItemChildClickListener(presenter);
        adapter.setOnItemClickListener(presenter);
       // adapter.setOnLoadMoreListener(presenter, recyclerView);
        // GridLayoutManager mgr=new GridLayoutManager(getContext(),3);
        LinearLayoutManager mgr = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(mgr);
        recyclerView.setNestedScrollingEnabled(false);
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void onStart() {
        super.onStart();
            if (showType==0){
            buttonSend.setVisibility(View.GONE);
        }else {
            buttonSend.setVisibility(View.VISIBLE);
        }
        if(planIdShowType==1||planIdShowType==2||
                planIdShowType==11||planIdShowType==12){
            buttonSend.setVisibility(View.VISIBLE);
        }else {
            buttonSend.setVisibility(View.GONE);
        }


    }
    @OnClick(R.id.button_send)
    public void dfdsf(){
        if (waybillExecId<1)
            return;
        Intent intent=new Intent(this, FeeAddAc.class);
        intent.putExtra("waybillExecId",waybillExecId);
        intent.putExtra("showType",1);//0 费用详情 不可操作  1 异常费用详情
        intent.putExtra("waybillNo",waybillNo);
        startActivityForResult(intent,1);
    }
    @Override
    public void refreshComplite(String... msg) {
        super.refreshComplite(msg);
        if (showType==0){
            List<Fee> list=adapter.getData();
            for (Fee fee : list) {
                fee.setShowType(0);
            }
            adapter.notifyDataSetChanged();
        }


    }

    @Override
    public void refreshNoData(String... msg) {
        super.refreshComplite(msg);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode== Constant.fineshFeeAdd){
            presenter.getExceptionFeeList(token,waybillExecId);
        }
    }
}
